package com.dap.batch.config;

import com.alibaba.dubbo.config.*;
import com.dap.batch.properties.ZkProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

/**
 * @description: dubbo服务注册中心配置
 * @author: Fesine
 * @createTime:2017/9/14 22:57
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2017/9/14 22:57
 */
public class DubboBaseConfig {

    @Autowired
    private ZkProperties zkProperties;

    /**
     * 注册中心bean配置
     * @return
     */
    @Bean
    public RegistryConfig registry() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setClient(zkProperties.getClient());
        registryConfig.setAddress(zkProperties.getAddress());
        registryConfig.setProtocol(zkProperties.getProtocol());
        registryConfig.setGroup(zkProperties.getGroup());
        return registryConfig;
    }

    /**
     * 应用bean配置
     * @return
     */
    @Bean
    public ApplicationConfig application() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("batch");
        applicationConfig.setDefault(true);
        return applicationConfig;
    }

    /**
     * 监控bean配置
     * @return
     */
    @Bean
    public MonitorConfig monitorConfig() {
        MonitorConfig mc = new MonitorConfig();
        mc.setProtocol(zkProperties.getProtocol());
        return mc;
    }

    /**
     * 引用bean配置
     * @return
     */
    @Bean
    public ReferenceConfig referenceConfig() {
        ReferenceConfig rc = new ReferenceConfig();
        rc.setMonitor(monitorConfig());
        return rc;
    }

    /**
     * 协议bean配置
     * @return
     */
    @Bean
    public ProtocolConfig protocol() {
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setPort(zkProperties.getPort());
        return protocolConfig;
    }

    /**
     * 提供者bean配置
     * @return
     */
    @Bean
    public ProviderConfig provider() {
        ProviderConfig providerConfig = new ProviderConfig();
        providerConfig.setMonitor(monitorConfig());
        return providerConfig;
    }
}
